package cn.bbs.ba.base;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;

import cn.bbs.ba.db.ADaoOperate;
import cn.bbs.ba.util.CommonUntil;

public class BaseDto extends HashMap
									implements Serializable {

	public static final long serialVersionUID = 1L;
	
//	private static final String UPDATE_FLAG = "UPDATE_FLAG";
	
	private static final String Error_Message = "ERRORMESSAGE";
	
	private static final String HOST_RETCODE = "hostRetCode";
	private static final String HOST_MESSAGE = "hostMessage";
	
	public BaseDto() {
//		setUpdateFlag(false);
	}
	public Object getValue(String key) {
		if (super.get(key.toUpperCase()) == null) {
			return "";
		}
		return super.get(key.toUpperCase());
	}
	
	public String getString(String key) {
		if (super.get(key.toUpperCase()) == null) {
			return "";
		}
		return CommonUntil.objToString(super.get(key.toUpperCase()));
	}
	public void setValue(String key, Object value) {
		super.put(key.toUpperCase(), value);
	}

	public Object getSQLID(String key) {
		return super.get(ADaoOperate.SQL_ID);
	}

	public void setSQLID(Object value) {
		super.put(ADaoOperate.SQL_ID, value);
	}
	
//	public boolean getUpdateFlag() {
//		return (Boolean)super.get(UPDATE_FLAG);
//	}
//
//	public void setUpdateFlag(boolean value) {
//		super.put(UPDATE_FLAG, value);
//	}
	
	public String getErroMessage() {
		return CommonUntil.objToString(super.get(Error_Message));
	}

	public void setErrorMessage(String value) {
		super.put(Error_Message, value);
	}
	public String getHostRetCode() {
		return CommonUntil.objToString(super.get(HOST_RETCODE));
	}

	public void setHostRetCode(String value) {
		super.put(HOST_RETCODE, value);
	}
	
	public String getHostMessage() {
		return CommonUntil.objToString(super.get(HOST_MESSAGE));
	}

	public void setHostMessage(String value) {
		super.put(HOST_MESSAGE, value);
	}
	
	 /**
     * 克隆DTO
     * <p>
     * public Object copyObject(Object objToCopy)
     * </p>
     * @return Object
     */
    public Object deepCopy() {

        Object obj;

        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(out);
            oos.writeObject(this);
            byte[] bs = out.toByteArray();
            InputStream in = new ByteArrayInputStream(bs);
            ObjectInputStream ios = new ObjectInputStream(in);
            obj = ios.readObject();
        }
        catch (Exception e) {
            e.printStackTrace();
            obj = new Object();
        }

        return obj;
    }
}
